package com.d2rv.camera;

import com.d2rv.offscreen.OffScreen3D;
import com.d2rv.settings.Settings;
import processing.core.PVector;

/**
 * This class is the manager of the class Camera used to control a camera. 
 * 
 * @author Darrieutort A., Dupouy A., Rossignol L., Van Poucke A.
 */
public class CameraManager {

    private Camera camera;

    /**
     * Default constructor.
     * 
     * @param position the position of the camera
     * @param target the target of the camera
     * @param up the up of the camera
     */
    public CameraManager(PVector position, PVector target, PVector up) {
        Settings settings = Settings.getInstance();
        this.camera = new Camera(position, target, up, new PVector((float)(settings.screenwidth()), (float)(settings.screenheight())));
    }

    /**
     * Calls the default processing camera used for the guide camera.
     * 
     * @param parent the current offscreen
     */
    public void camera(OffScreen3D parent) {
        parent.camera(this.camera.position().x, this.camera.position().y, this.camera.position().z,
                this.camera.target().x, this.camera.target().y, this.camera.target().z,
                this.camera.up().x, this.camera.up().y, this.camera.up().z);
    }

    /**
     * Updates the position and the target of the camera.
     * 
     * @param position the new position of the camera
     * @param target the new target of the camera
     */
    public void updateCamera(PVector position, PVector target) {
        this.camera.position(position);
        this.camera.target(target);
    }

    /**
     * Updates the zoom factor of the camera used in the guide map.
     * 
     * @param zoom the new zoom factor
     */
    public void updateZoomCamera(float zoom) {
        this.camera.zoom(zoom);
    }

    /**
     * Returns the zoom factor of the camera.
     * 
     * @return the zoom factor of the camera
     */
    public float zoomCamera() {
        return this.camera.zoom();
    }

    /**
     * Returns the position of the camera.
     * 
     * @return the position of the camera
     */
    public PVector positionCamera() {
        return this.camera.position();
    }

    /**
     * Updates the frustum of the camera with a offset eye.
     * 
     * @param parent the current offscreen
     * @param offset the offset eye
     */
    public void setCamera(OffScreen3D parent, float offset) {
        this.camera.setCamera(parent, offset);
    }
}